#include "FileContent.h"

void init(FileContent* F)
{
	F->start = 0;
	F->end = 0;
}

void pushF(FileContent* F, Node* node)
{

	if(isEmpty(F))
	{
		F->start = node;
		F->end = node;
	}
	else
	{
		F->end->next = node;
		node->next = 0;
		F->end = node;
	}
}

Node* getStart(FileContent* F)
{
	return F->start;
}

int isEmpty(FileContent* fila)
{
	if(fila->start == 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int tamBin(int val)
{
    int d,tam;
    tam = 0;
    d=val;
    if(val == 0){
        return 1;
    }
    while(d>0)
    {
        d = (d<<1);
        tam ++;
    }
    return 32-tam;
}

char* intToChar(short int n, short int tamanho)
{
    int c, d, count;
    char *binario = NULL;

    count = 0;
    binario = (char*)malloc(tamanho+1);

    for (c = tamanho-1; c>=0; c--)
    {
        d = n >> c;

        if ( d & 1 )
            *(binario+count) = 1 + '0';
        else
            *(binario+count) = 0 + '0';

        count++;
    }
    *(binario+count) = '\0';

    return  binario;
}
char* intToCharC(char n, short int tamanho)
{
    int c, d, count;
    char *binario;

    count = 0;
    binario = (char*)malloc(tamanho+1);

    for (c = tamanho-1; c>=0; c--)
    {
        d = n >> c;

        if ( d & 1 )
            *(binario+count) = 1 + '0';
        else
            *(binario+count) = 0 + '0';

        count++;
    }
    *(binario+count) = '\0';
    //printf("Tamanho: %d\n", count);
    return  binario;
}
